How to sort group and aggregate values in a list of nested dictionaries